import type { StixMalwareAnalysis, StoreEntityMalwareAnalysis } from './malwareAnalysis-types';
import { buildStixDomain } from '../../database/stix-converter';
import { INPUT_HOST_VM, INPUT_OPERATING_SYSTEM, INPUT_SAMPLE, INPUT_INSTALLED_SOFTWARE, INPUT_ANALYSIS_SCO } from './malwareAnalysis-types';

const convertMalwareAnalysisToStix = (instance: StoreEntityMalwareAnalysis): StixMalwareAnalysis => {
  const stixDomainObject = buildStixDomain(instance);
  return {
    ...stixDomainObject,
    version: instance.version,
    product: instance.product,
    host_vm_ref: instance[INPUT_HOST_VM]?.standard_id,
    operating_system_ref: instance[INPUT_OPERATING_SYSTEM]?.standard_id,
    installed_software_refs: (instance[INPUT_INSTALLED_SOFTWARE] ?? []).map((m) => m.standard_id),
    configuration_version: instance.configuration_version,
    modules: instance.modules,
    analysis_engine_version: instance.analysis_engine_version,
    analysis_definition_version: instance.analysis_definition_version,
    submitted: instance.submitted,
    analysis_started: instance.analysis_started,
    analysis_ended: instance.analysis_ended,
    result_name: instance.result_name,
    result: instance.result,
    analysis_sco_refs: (instance[INPUT_ANALYSIS_SCO] ?? []).map((m) => m.standard_id),
    sample_ref: instance[INPUT_SAMPLE]?.standard_id,
  };
};

export default convertMalwareAnalysisToStix;
